#ifndef MAIN_H
#define MAIN_H

#include "gd32f30x.h"
#include "systick.h"
#include "BSP_Config.h"
#include "gd32f30x_gpio.h"
#include "IO.h"
#include "CAN.h"

#include "ADC.h"
#include "PWM.h"
#include "hems_can_def.h"
#include "app_can.h"
#include "app_output.h"
#include "app_input.h"
#include "WDT.h"
#include "flash.h"
#include <string.h>
#include "usart.h"
#include "Lib.h"
#include "PI.h"
#include "app.h"
#define HEM1601_CAN_IO
#define ACK_TX_ID  0x700
#define YEAR ((((__DATE__[7] - '0')*10 + (__DATE__[8] - '0'))*10 + (__DATE__[9] - '0'))*10 + (__DATE__[10] - '0'))
#define MONTH (__DATE__[2] == 'n' ? 0\
              :__DATE__[2] == 'b' ? 1\
              :__DATE__[2] == 'r' ? (__DATE__[0] == 'M' ? 2 : 3)\
              :__DATE__[2] == 'y' ? 4\
              :__DATE__[2] == 'n' ? 5\
              :__DATE__[2] == 'l' ? 6\
              :__DATE__[2] == 'g' ? 7\
              :__DATE__[2] == 'p' ? 8\
              :__DATE__[2] == 't' ? 9\
              :__DATE__[2] == 'v' ? 10 : 11)
#define DAY ((__DATE__[4] == ' ' ? 0 : __DATE__[4] - '0')*10 + (__DATE__[5] - '0'))

#define HOUR    ((__TIME__[0] - '0')*10 + __TIME__[1] - '0')
#define MINUTE  ((__TIME__[3] - '0')*10 + __TIME__[4] - '0')
#define SECOND  ((__TIME__[6] - '0')*10 + __TIME__[7] - '0')

//定时器是500us
#define TIME_OUT_1MS   2
#define TIME_OUT_2MS   4
#define TIME_OUT_5MS   10
#define TIME_OUT_10MS  20
#define TIME_OUT_20MS  (2*TIME_OUT_10MS)
#define TIME_OUT_50MS  (5*TIME_OUT_10MS)
#define TIME_OUT_60MS  (6*TIME_OUT_10MS)
#define TIME_OUT_97MS  (97*TIME_OUT_1MS)
#define TIME_OUT_100MS 200
#define TIME_OUT_200MS 400
#define TIME_OUT_250MS 500
#define TIME_OUT_500MS 1000
#define TIME_OUT_1S    2000
#define TIME_OUT_5S    (5*TIME_OUT_1S)  
#define TIME_OUT_10S   (10*TIME_OUT_1S)

#define APP_LOAD_ADDR_OFFSET 0x00008000  /*应用程序偏移地址*/

extern uint32_t gCanRxFaultCnt;
extern uint8_t gCanTxFaultSn;
extern void tick_Callback(void);

extern uint32_t ul_radio_status_led_timeout_cnt;
extern uint8_t gStatusLEDFlickerTimeoutSn;
#endif

